<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

$errors = array();

if ($route->POST("act") == "post")
{
	$user_id = $user->getUserId();
	$priority = UV::readInt(strip_tags($route->POST("priority")));
	$text = UV::readMQ(strip_tags($route->POST("text")));
	if (!$priority)
		$priority = 0;
	
	$rumor = $db->sendQuery("insert into `rumors` values(NULL,'$user_id','$text','$priority')");
	if (!$rumor)
		$errors[] = "Не удалось пустить слух. Возможно он очень лживый...";
	
	if (count($errors) == 0)
		goToPage("/admin/rumors/view");
}

require_once ADMIN.DS.HEAD;
?>
<div class='full'>
	<div class="submenu_container">
		<a class="submenu_button" href='/admin/rumors/view'>Список</a>
		<a class="submenu_button submenu_button_active" href='/admin/rumors/create'>Пустить слух</a>
	</div>
	<h3>Пустить слух</h3><?php
		if (count($errors) != 0)
			echo "<p style='color:red'>".implode("<br />",$errors)."</p>";
	?><form method='post'>
		<input type='hidden' name='act' value='post' />
		<table cellspacing='10'>
			<tr>
				<td width='150px'><label for='priority'>Приоритет</label></td>
				<td width='300px'><input type='text' id='priority' name='priority' style="width:20%;" value='0' /></td>
			</tr>
			<tr>
				<td><label for='text'>Текст</label></td>
				<td><textarea id='text' name='text' rows='5' style="width:100%"></textarea></td>
			</tr>
			<tr>
				<td colspan='2' align='right'><input type='submit' style="padding:5px 20px" value="Пустить" /></td>
			</tr>
		</table>
	</form>
</div>

<?php require_once ADMIN.DS.FOOTER; ?>